package org.nyt.medicalstore.service.impl;

import org.nyt.medicalstore.model.PurchaseRecord;
import org.nyt.medicalstore.repository.PurchaseRecordRepository;
import org.nyt.medicalstore.service.PurchaseRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class PurchaseRecordServiceImpl implements PurchaseRecordService {
    @Autowired
    private PurchaseRecordRepository purchaseRecordRepository;

    @Override
    public PurchaseRecord savePurchaseRecord(PurchaseRecord purchaseRecord) {
        return purchaseRecordRepository.save(purchaseRecord);
    }

    @Override
    public PurchaseRecord getPurchaseRecordById(Long id) {
        Optional<PurchaseRecord> purchaseRecord = purchaseRecordRepository.findById(id);
        return purchaseRecord.orElse(null);
    }

    @Override
    public List<PurchaseRecord> getAllPurchaseRecords() {
        return purchaseRecordRepository.findAll();
    }

    @Override
    public void deletePurchaseRecord(Long id) {
        purchaseRecordRepository.deleteById(id);
    }
} 